home *** CD-ROM | disk | FTP | other *** search
/ Amoszine 5 / Amoszine 5.adf / arts / STRUCTURING.asc.cm / STRUCTURING.asc.cm
Text File  |  1992-02-26  |  5KB  |  144 lines

  1. @1                       STRUCTURING YOUR PROGRAMS
  2.                        -------------------------
  3.  
  4.                          @7 By Richard Martin
  5.  
  6. @6
  7.  
  8.       How do you structure your programs? It is a question that can 
  9.       cause a lot of people a lot of pain.  If you know anyone who
  10.       has done a A level or has a degree in computing, the first 
  11.       thing they will say (usually!) is yuck!  The structure of your
  12.       mega smash hit game is terrible. Doesn't bother them (if they
  13.       are like my brother) if its the most playable game since the
  14.       excellent FRANTIC FREDDIE. (That game is cool!). So what is
  15.       this "structure" they are going on about ?
  16.  
  17. @3      Basically, the structure is how the program source is set out.
  18.       The main thing to remember about the structure of your program
  19.       is that the most important thing is that YOU understand it and
  20.       YOU can easily de-bug it. However, the rest of the article is
  21.       about how I structure my programs now. It does not mean if you
  22.       read this article this is THE way in which every program must 
  23.       be written. If you are happy with the structure of YOUR program
  24.       then keep with it. Just because a program is structure so some
  25.       stuck up professor thinks its good doesn't actually mean the 
  26.       program is no good. Look at the source code to some of Brian 
  27.       Bells programs (On MAC you dolt!). They have lots of "GOSUBS"
  28.       in them. So what. People who go on about "structured coding "
  29.       would probably have a heart attack. But the actual programs 
  30.       are absolutely brilliant and I have learnt a great deal from
  31.       them. 
  32.  
  33.       The first thing I tend to do is comment my work. You may think
  34.       that I would do this anyway, because most of the code I write
  35.       usually ends up on DIDSMAG. (As I edit it you see!). This is
  36.       not the case. I find that if I put comments on every routine,
  37.       and space my work out with comments then it makes the seperate
  38.       commands stand out. The author of the AMOSSIBLE series of PD
  39.       disks has these huge blocks of REM statements then a command
  40.       and a huge block of REM'S again. I find that it takes a while
  41.       to pick out a command from his explanation! You don't quite
  42.       get what I am getting at? Here is an example
  43. @4
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.       ' This routine will print my magazines name on the screen
  51.       ' 20 times
  52.       '
  53.       For I=1 to 20
  54.       Print"DIDSMAG: 9 BLUNDELL AVE, BIRK...(Oh no you don't you are
  55.       not going to get a plug in that easy! - Ed)
  56.       Next I
  57.       ' 
  58.       ' Now scroll the screen off
  59.       '
  60.       Def Scroll 1,0,0 to 320,200,-1,0
  61.       '
  62.       ' Start scrolling
  63.       '
  64.       Scroll 1
  65.       '
  66. @3    
  67.       Just by looking at it you can see the scroll command. But look
  68.       closely at the FOR/NEXT loop. Its no to easy to see whats going
  69.       on. Just press F3 in the editor and it INDENTS your programs
  70.       This makes it far easier to see whats going on. I indent my 
  71.       programs all the time. 
  72. @4
  73.       ' The For/Next now becomes:
  74.       '
  75.       For I=1 to 20
  76.             Print "DIDSMAG: 9 BLUNDELL AVE..BIRKDALE..(My god you are
  77.             (persistant!- Ed)
  78.       Next I
  79.       '
  80. @3    
  81.       I find this is easier to read. The final thing I am going to
  82.       look at are the actual routines. There are two ways of Storing
  83.       them: Procedures and Labels. I have started using procedures 
  84.       for everything I do. I thought I'd tell you why. Up until a
  85.       month or so ago I used LABELS and Gosubs. But the games I am
  86.       programming which use labels are becoming HUGE. (That is Uridi-
  87.       Star and Mouth Man (For WAC) in case you were interested. No?
  88.       Okay then.) With my very latest project: Space Adventures I
  89.       have used procedures for everything I can. I find the ability
  90.       to fold them up is brilliant. I can then have what would be 30
  91.       screens of code in just 2! When I find a bug I just need to
  92.       unfold the relevant procedures with out having to scroll back
  93.       and forth. Procedures can also do easy Parameter passing.
  94. @4
  95.  
  96.  
  97.  
  98.       An example  for you is:
  99.  
  100.       ' The Labels:
  101.       '
  102.       X=50:Y=150:I=50:N=3:Gosub placeBobz
  103.       '
  104.       PLACEBOBZ:
  105.       '
  106.       For COUNT=1 TO N
  107.             Bob COUNT,X,Y,I
  108.       Next COUNT
  109.       '
  110.  
  111.       ' Using Procedures:
  112.       '
  113.       '
  114.       PLACEBOBZ[50,50,50,3]
  115.       '
  116.       Procedure[X,Y,I,N]
  117.       For COUNT=1 to N
  118.             Bob COUNT,X,Y,I
  119.       Next COUNT
  120.       End Proc
  121.  
  122.  
  123.  
  124. @3
  125.       As I said earlier though this is not how you MUST code. If you
  126.       have not yet devolped a style that works brillantly yet then I
  127.       suggest you try it out. You never know. You could like it!
  128.  
  129.       If you need more help, want to tell me about your latest project,
  130.       moan about anything or give me some source code or AMOS programs
  131.       and games, or in fact anything else then do not hesitate to write
  132.       to me at:
  133. @5
  134.       Richard Martin
  135.       9 Blundell Avenue
  136.       Birkdale
  137.       SouthPort
  138.       PR8 4TA
  139. @3      
  140.       You can also get issues of DidsMag from here. Send a S.S.A.E and
  141.       two disks for the latest issue. Or you can get it from F1's PD
  142.       Library. Its really very good. 
  143.       
  144.       Richard Martin.